package com.zcxy.sys.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.zcxy.anotation.Log;
import com.zcxy.core.bean.PageQuery;
import com.zcxy.core.bean.Response;
import com.zcxy.sys.entity.SysRole;
import com.zcxy.sys.pojo.SysRoleVo;
import com.zcxy.sys.service.ISysRoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * @author zcc
 * @version 1.0.0
 * @ClassName SysRoleController.java
 * @Description 角色
 * @createTime 2020-06-02
 */
@RestController
@RequestMapping("/api/sysRole")
@Api(tags = "<font  color='red'>角色管理</font>")
@Slf4j
@JsonInclude(JsonInclude.Include.NON_NULL)
public class SysRoleController {
    @Autowired
    private ISysRoleService iSysRoleService;

    @Log(value = "获取(角色)分页数据列表")
    @PostMapping(value = "/queryPageList")
    @ApiOperation(value = "获取(角色)分页数据列表", notes = "获取(角色)分页数据列表")
    public Response<IPage<SysRoleVo>> queryPageList(@RequestBody PageQuery<SysRole> queryVo) {
        return Response.ok(iSysRoleService.queryPageList(queryVo));
    }


    @Log(value = "获取(启用角色)数据列表")
    @GetMapping(value = "/queryList")
    @ApiOperation(value = "获取(启用角色)数据列表", notes = "获取(启用角色)数据列表")
    public Response<List<SysRoleVo>> queryList() {
        return Response.ok(iSysRoleService.queryList());
    }


    @Log(value = "新增(角色)数据")
    @PostMapping(value = "/add")
    @ApiOperation(value = "新增(角色)数据", notes = "新增(角色)数据")
    public Response addSysRole(@RequestBody @Validated SysRole queryVo) {
        iSysRoleService.addSysRole(queryVo);
        return Response.ok();
    }

    @Log(value = "另存新增(角色)数据")
    @PostMapping(value = "/addByOne")
    @ApiOperation(value = "另存新增(角色)数据", notes = "另存新增(角色)数据")
    public Response addByOne(@RequestBody @Validated SysRole queryVo) {
        queryVo.setId("");
        iSysRoleService.addSysRole(queryVo);
        return Response.ok();
    }

    @Log(value = "修改(角色)数据")
    @PutMapping(value = "/update")
    @ApiOperation(value = "修改(角色)数据", notes = "修改(角色)数据")
    public Response updateSysRole(@RequestBody SysRole queryVo) {
        iSysRoleService.updateSysRole(queryVo);
        return Response.ok();
    }

    @Log(value = "删除(角色)数据")
    @PostMapping(value = "/del")
    @ApiOperation(value = "根据主键删除(角色)数据", notes = "根据主键删除(角色)数据")
    public Response removeSysRole(@RequestParam("id") String id) {
        iSysRoleService.removeSysRole(id);
        return Response.ok();
    }

    @Log(value = "批量删除(角色)数据")
    @DeleteMapping(value = "/dels")
    @ApiOperation(value = "批量删除(角色)数据", notes = "批量删除(角色)数据")
    public Response removeSysRoles(@RequestBody List<String> ids) {
        iSysRoleService.removeAllSysRole(ids);
        return Response.ok();
    }

    @Log(value = "查看(角色)")
    @GetMapping(value = "/view")
    @ApiOperation(value = "查看(角色)数据", notes = "查看(角色)数据")
    public Response<SysRoleVo> viewSysRole(@RequestParam("id") String id) {
        return Response.ok(iSysRoleService.viewSysRole(id));
    }
}
